package servlet;

import bean.Result;
import com.google.gson.Gson;
import dao.UserOrdersDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "RejectedServlet", value = "/RejectedServlet.s")
public class RejectedServlet extends HttpServlet {

    UserOrdersDao dao = new UserOrdersDao();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        final String orderid = request.getParameter("orderid");
        final String detailid = request.getParameter("detailid");

        Result result;

        int res = dao.rejectedMin(detailid);
        int res2 = dao.rejectedMax(orderid);

        if (res == 1 && res2 == 1){
            result = new Result(1,"提交审核中...",null);
        } else {
            result = new Result(0,"提交失败!",null);
        }
        final String json = new Gson().toJson(result);
        response.getWriter().append(json);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
